package com.my.event.publisher;

import com.my.core.domain.log.LogApi;
import com.my.core.util.spring.SpringUtil;
import com.my.core.util.WebUtil;
import com.my.event.domin.ApiLogEvent;
import com.my.event.utils.LogAbstractUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * @author timo 2021/2/25
 */

public class ApiLogPublisher {
    public ApiLogPublisher() {
    }

    public static void publishEvent(String methodName, String methodClass, String value, long time) {
        HttpServletRequest request = WebUtil.getRequest();
        LogApi logApi = new LogApi();
        logApi.setType("1");
        logApi.setTitle(value);
        logApi.setTime(String.valueOf(time));
        logApi.setMethodClass(methodClass);
        logApi.setMethodName(methodName);
        LogAbstractUtil.addRequestInfoToLog(request, logApi);
        Map<String, Object> event = new HashMap(16);
        event.put("log", logApi);
        SpringUtil.publishEvent(new ApiLogEvent(event));
    }
}
